﻿using Microsoft.Extensions.DependencyInjection;
using Natty.NetCore.Quartz.Factory;
using Natty.NetCore.Quartz.Job;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Text;

namespace Natty.NetCore.Quartz
{
    public static class ServiceCollectionExtensions
    {
        public static void AddJob(this IServiceCollection services)
        { 
            // Add Quartz services
            services.AddSingleton<IJobFactory, SingletonJobFactory>();
            services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();

            // Add our job
            services.AddSingleton<HelloWorldJob>();
            services.AddSingleton<IntroduceJob>();

            services.AddSingleton(new JobSchedule(
               jobType: typeof(HelloWorldJob),
               cronExpression: "0/2 * * * * ? *")); // run every 2 seconds

            services.AddSingleton(new JobSchedule(
                jobType: typeof(IntroduceJob), cronExpression: "0/2 * * * * ? *"));

            services.AddHostedService<QuartzHostedService>();
        }
    }
}
